using UnityEditor;
using UnityEngine;

public class CopyUIPath
{
    [MenuItem("Assets/Mini Tools/UI/Copy UI Path", false, 1)]
    [MenuItem("GameObject/Mini Tools/GameObject/Copy UI Path", false, 1)]
    private static void Main()
    {
        var go = Selection.activeGameObject;
        if (go == null) return;

        string path = GetPath(go.transform);

        EditorGUIUtility.systemCopyBuffer = path;

        Debug.Log($"path : {path}");
        Debug.Log("Copy UI Path Complete");
    }

    private static string GetPath(Transform trans)
    {
        if (trans == null)
        {
            return string.Empty;
        }

        string path = trans.name;

        while (trans.parent != null)
        {
            trans = trans.parent;
            path = $"{trans.name}/{path}";

            if (trans.name.ToLower().EndsWith("root"))
            {
                break;
            }
        }

        return path;
    }
}
